from .database import Database
from .history import History
from .config import Config
from .video import Video

from plugins.plugman import PlugMan

class Rosemary:

    def __init__(self) -> None:
        self.version    = "0.0.2"
        self.config     = Config()
        self.database   = Database()
        self.history    = History()

        self.plugman    = PlugMan(self.history, self.config)

    def init_plugins(self) -> None:
        self.plugman.load_plugins()
        self.install_default_plugins()

    def install_default_plugins(self) -> None:
        if len(self.plugman.plugins) == 0:
            query = input("Do you wan't install default Invidious plugins? (y/n): ")
            if query == "y": self.plugman.install_default_plugins()

    def get_plugins(self) -> list:
        return [plugin.to_json() for plugin in self.plugman.plugins]

    def get_plugin_items(self, id, params) -> list:
        plugin = self.plugman.get_plugin_by_id(id)
        return plugin.get_items(params)

    def insert_video_to_history(self, video) -> None:
        video = Video().from_history_dict(video)
        self.history.insert(video)

    def download_video(self, video) -> None:
        video = Video().from_history_dict(video)
        return video.download()



